package net.xi.dmhome.controller;

import cn.hutool.core.map.MapUtil;
import net.xi.dmhome.Utils.ForeCastUtil;
import net.xi.dmhome.entity.Forecast;
import net.xi.dmhome.handler.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: jxhu
 * @Description:
 * @Date Created in 2021-04-05 15:18
 * @Modified By:
 */

@RestController
@RequestMapping("/forecast")
public class ForecastController {

    private ForeCastUtil foreCastUtil = new ForeCastUtil();

    @PostMapping("/test")
    public Result forecast(@Validated @RequestBody(required = false)Forecast forecast){
        System.out.println(forecast.toString());
        Integer score = 0;
        Integer age = forecast.getAge();
        Integer ageScore = foreCastUtil.countAge(age);
        score+=ageScore;
        Double weight = forecast.getWeight();
        Double height = forecast.getHeight();
        Integer countBodyMass = foreCastUtil.CountBodyMass(weight, height);
        score+=countBodyMass;
        Integer relatives = forecast.getRelatives();
        Integer countrelatives = foreCastUtil.countRelatives(relatives);
        score+=countrelatives;
        String sex = forecast.getSex();
        Integer waistline = forecast.getWaistline();
        Integer countWaistLine = foreCastUtil.CountWaistLine(sex, waistline);
        score+=countWaistLine;
        Integer sbp = forecast.getSbp();
        Integer countSbp = foreCastUtil.CountSbp(sbp);
        score+=countSbp;
        String suggestion = foreCastUtil.Suggestion(score);
        return Result.success(200,"success", MapUtil.builder().
                put("score",score).
                put("suggest",suggestion).
                map());

    }



}
